﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using Jumpton.Data;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class BannerManager:BusinessLogic
    {
        //public ObjectTable GetCourseTable()
        //{
        //    return new ObjectTable(typeof(BANNERS));
        //}
        public ObjectTable GetCourseTable(decimal domainID,string chainCode)
        {
            return new ObjectTable(typeof(BANNERS), "this.DOMAINID='" + domainID + "' and this.CHAINCODE = '" + chainCode + "'");
        }

        public BANNERS Load(int id)
        {
            return (BANNERS)ObjectRow.Load(typeof(BANNERS), string.Format("this.ID='{0}'", id));
        }

        public BANNERS LoadCode(string code, decimal domainID, int ID, string CHAINCODE)
        {
            return (BANNERS)ObjectRow.Load(typeof(BANNERS), string.Format("this.CODE='{0}' and this.DOMAINID={1} and this.ID<>'{2}' AND this.CHAINCODE='{3}'", code, domainID, ID, CHAINCODE));
        }

        public bool Save(BANNERS banner)
        {
            bool Successful = false;
            if (this.LoadCode(banner.CODE, banner.DOMAINID, banner.ID, banner.CHAINCODE) != null)
            {
                throw new Exception("代码已使用");
            }
            if (banner != null)
            {
                try
                {
                   
                    banner.Save();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message;throw err;
                    Successful = false;
                }
            }

            return Successful;
        }

        public bool Delete(BANNERS banner)
        {
            bool Successful = false;
            if (banner != null)
            {
                try
                {
                    banner.Delete();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message;throw err;
                    Successful = false;
                }
            }

            return Successful;
        }
    }
}
